package com;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

class CycleLock{
    AtomicReference<Thread> atomicReference = new AtomicReference<>();

    // 获取锁的   因为需要的是线程，所以 不需要传参数
 public  void  mylock(){
     Thread thread = Thread.currentThread();
     // 一直  尝试拿锁,直到获取成功
     while(!atomicReference.compareAndSet(null,thread)){
     }
 }
 // 释放锁的方法，修改期望原址为 null 就可以了
 public  void  unlock(){
     Thread thread = Thread.currentThread();
     atomicReference.compareAndSet(thread,null);
 }

}

class  Test{
    public static void main(String[] args) {

    }
}

